/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package biofilter.filters;

import biofilter.factories.MappedPositionFactory;
import biofilter.records.FileNameRecord;
import biofilter.records.GFFRecord;
import biofilter.records.Record;
import biofilter.exceptions.InvalidRecordException;

/**
 * This filter takes an arbitrary MappedPosition complient Record and converts it
 * to GFF format.  The intention is that the filter takes a filename containing
 * the path to files of mapped reads (all of the same type) and streams the mapped
 * locations from the files in GFF common format when getRecord() is called.
 * @author Daniel Quest
 * @date   April 13 2010
 */
public class RecordsFile2GFF extends SplitFileNoMemoryFilterBase {

    public RecordsFile2GFF(){
        mpf = new MappedPositionFactory();
    }

    public RecordsFile2GFF(String mappedPositionType){
        mpf = new MappedPositionFactory(mappedPositionType);
    }

    private MappedPositionFactory mpf = null;
    protected GFFRecord transformRecord(Record r) throws InvalidRecordException {
        if (!(r instanceof FileNameRecord)) {
            throw new RuntimeException("type mismatch, expected FileNameRecord");
        }if(r == null){
            throw new RuntimeException("FileNameRecord is null!");
        }
        GFFRecord gff = mpf.GFFconverter(r);
        return gff;

    }
    
    public void setMappedPositionType(String type){
        mpf.setMappedPositionType(type);
    }

}
